{extend name="default/template/base_index" /}


{block name="area_header"}
    <link type="text/css" rel="stylesheet" href="__CDN__/select2/4.0.0/css/select2.min.css" />
    <script type="text/javascript" src="__CDN__/select2/4.0.0/js/select2.full.js"></script>
    <script type="text/javascript" src="__CDN__/select2/4.0.0/js/i18n/zh-CN.js"></script>
    <script type="text/javascript" src="__CDN__/zeroclipboard/2.2.0/ZeroClipboard.min.js" ></script>


{/block}

{block name="area_body"}
    {include file="default/Widget/topbar" /}
    <div class="admin-main container-fluid">
        {include file="default/Widget/left" /}
        <div class="admin-main-content">
            {include file="default/Widget/breadcrumb" /}

            <div class="filter-controls">
                &nbsp;&nbsp;快速切换到&nbsp;&nbsp;
                <select style="padding: 5px;border-radius: 3px;" onchange="changeUidGroup(this)">
                    <volist name="groups" id="group">
                        <option value="{$group.id}:{$group.name}"
                                <if condition="$groupid eq $group['id']">
                                    selected="selected"
                                </if>
                                >{$group.name}</option>
                    {/volist}
                </select>
                <hr />
            </div>
            <div class="form-control-static">
                        <form class="addForm" action="{:url('SpecialGroup/addUidMgroup')}">
                            <input type="hidden" name="groupid" value="{$groupid}"/>
                            <input type="hidden" name="groupname" value="{$groupname}"/>
                            <select style="width:220px;padding: 10px 15px;font-size: 15px;line-height: 1.42857143;" id="user_select2" name="uid" class="form-control" required>
                                <option></option>
                            </select>
                        &nbsp;&nbsp;
                            <a target-form="addForm" class="ajax-post btn btn-primary" href="{:url('SpecialGroup/addUidMgroup')}" autofocus="autofocus"><i class="fa fa-plus"></i>添加到{$groupname}</a>
                           <!-- <a href="{:url('SpecialGroup/addMember')}"  class="btn btn-primary btn-sm" >
                                <i class="fa fa-plus"></i>
                            </a>-->
                        </form>

                        <!--<input type="text" class="required form-control input-short" name="id" id="inputtitle" placeholder="请输入用户ID">-->

            </div>

            <div class="table-responsive">
                <table class="table table-striped table table-hover  table-condensed">
                    <thead>
                    <tr>
                        <th>
                            <input type="checkbox" class="selectall" onclick="myUtils.selectall(this,'.selectitem');" />ID
                        </th>
                        <th>
                            用户
                        </th>
                        <th>
                            等级
                        </th>
                        <th>
                            创建时间
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td colspan="5" class="text-center" >{:L('NO_DATA')}</td>
                        </tr>
                    {/empty}
                    {volist name="list" id="vo"}
                        <tr>
                            <td><input type="checkbox" value="{$vo.id}" name="ids[]" class="selectitem" />{$vo.id}</td>
                            <td>{$vo.nickname}</td>
                            <td>{$vo.name}</td>
                            <td>{$vo.createtime|date='Y-m-d H:i:s',###}</td>
                            <td>
                                <!--<a href="{:url('SpecialGroup/memberUpdate',array('id'=>$vo['id']))}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i>{:L('BTN_EDIT')}</a>-->
                                <if condition=" is_administrator() ">
                                    <a href="{:url('SpecialGroup/deleteUidMgroup',array('id'=>$vo['id']))}" class="btn btn-danger btn-sm ajax-get confirm"><i class="fa fa-trash-o"></i> {:L('BTN_DELETE')}</a>
                                </if>
                            </td>

                        </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </div>

    </div>
{/block}

{block name="area_footer"}
    <script type="text/javascript">
        $(function(){

            $("#groups").change(function(){
                $(".groupForm").submit();
            });
            $("#addtogroup").text("添加到"+$("#groups").find("option:selected").text());
            $("#user_select2").select2({
                placeholder: "输入用户uid或昵称查询"
                ,
                language: "zh-CN",
                ajax: {
                    url: "{:url('Member/select')}",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        var queryParameters = {
                            q: params.term
                        }

                        return queryParameters;

                    },
                    processResults: function (data, page) {
                        if(!data.info){
                            data.info = new Array();
                            data.info['nodata']="无相关数据";
                        }
                        // parse the results into the format expected by Select2.
                        // since we are using custom formatting functions we do not need to
                        // alter the remote JSON data
                        return {
                            results: data.info
                        };
                    },
                    cache: true
                },
                minimumInputLength: 0,
                templateSelection: function (repo) {
                    return repo.nickname || repo.text;
                },
                templateResult: function (repo) {

                    if (repo.loading) return repo.text;
                    if(repo.nodata) return repo.nodata;
//    				var markup = '<div>'+repo.nickname+'</div>';
                    var markup = '<div>[uid:'+repo.uid+'] '+repo.nickname+'</div>';
                    return markup;
                },
            });
        })

        function changeUidGroup(group){
            var m=group.value.indexOf(':');
            var id=group.value.substring(0,m);
            var name=group.value.substring(m+1);
           // alert(id+"   "+name);
            window.location.href="{:url('SpecialGroup/uidMgroupIndex')}"+"?id="+id+"&groupname="+name;
        }
    </script>
{/block}